﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using ESOL.Common.Entity;
using ESOL.Business.Mst;
using ESOL.Common;
using ESOL.Business.Inv;

namespace ESOL.WinUI.Inv
{
    public partial class frmMaintainSetFixedQty : BaseForm.frmBaseDialogyMaintainForm
    {
        #region Variable
        public InvStorageEntity SelectedStorage { get; set; }
        #endregion

        #region Constructor
        public frmMaintainSetFixedQty()
        {
            InitializeComponent();
        }
        #endregion

        #region Functions
        private void SetFields()
        {
            if (SelectedStorage == null)
            {
                return;
            }
            txtProductCode.Text = MstProductBs.GetMstProductTypeByID(SelectedStorage.ProductId).ProductCode;
            txtProductName.Text = MstProductBs.GetMstProductTypeByID(SelectedStorage.ProductId).ProductName;
            txtFixedQty.Text = SelectedStorage.FixedQty.ToString();

        }
        private void SetEntity()
        {
            SelectedStorage.FixedQty = Convert.ToDecimal(txtFixedQty.Text);
            SelectedStorage.LastModifiedBy = CommonParameter.CurrentUser.PersonId;
            SelectedStorage.LastUpdateDate = DateTime.Now;
        }
        private bool CheckData()
        {
            if (string.IsNullOrEmpty(txtFixedQty.Text))
            {
                MessageBox.Show("安全库存不能为空！", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return false;
            }
            return true;
        }
        private bool Save()
        {
            try
            {
                if (CheckData() == false)
                {
                    return false;
                }
                    SetEntity();
                    bool isSuccessful = InvStorageBs.UpdateInvStorage(SelectedStorage);
                    if (!isSuccessful)
                    {
                        MessageBox.Show("修改失败！", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return false;
                    }
                
                return true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return false;
            }
        }
        #endregion

        private void frmMaintainSetFixedQty_Load(object sender, EventArgs e)
        {
            SetFields();
        }
        protected override void Click_Save()
        {
            if (Save())
            {
                this.DialogResult = DialogResult.OK;
            }
        }


    }
}